CC = g++
LD = g++
BUFSIZE = 512
DEFSIZE = 512
DEFINES = -DMAX_SIZE=$(BUFSIZE) #-DC_STYLE=$(STYLE)
FILE =
STYLE =
DEFSTYLE = C
CFLAGS = -Wall -O3
LDFLAGS =
SOURCES = main.cpp lex.cpp lexeme.cpp types.cpp recognizer.cpp f_grammar.cpp environment.cpp evaluator.cpp
OBJS = main.o lex.o lexeme.o types.o recognizer.o f_grammar.o environment.o evaluator.o
NAME = dpl

.PHONY: clean test rebuild all

$(NAME) : $(OBJS)
	@echo "Linking..."
	$(LD) $(LDFLAGS) $(OBJS) -o $(NAME)
	@echo "Done Linking"
	@echo "Default buffer size is" $(BUFSIZE)
#ifeq ($(strip $(STYLE)), $(strip $(DEFSTYLE)))
#	@echo "Using C Style Lex"
#else
#	@echo "Using F Style Lex"
#endif


%.o: %.cpp
	$(CC) $(DEFINES) $(CFLAGS) -c $<

clean:
	rm -rf $(OBJS)
	rm -rf $(NAME)

test: $(NAME)
	@echo "File to be parsed:" $(FILE)
	@echo "Mode: "$(TYPE)
	@echo "Buffer size:" $(BUFSIZE)
#ifeq ($(strip $(STYLE)), $(strip $(DEFSTYLE)))
#	@echo "Style: C"
#else
	@echo "Style: F"
#endif
ifeq ($(strip $(FILE)),)
	$(error No file input. Please run with 'FILE=<file>'.)
endif
ifeq ($(strip $(TYPE)),)
	$(error No type input. Please run with '-<R or E>'.)
endif
	@echo "Beginning test with " $(FILE) " and " $(TYPE)
	./$(NAME) $(FILE) $(TYPE)
	@echo "Done with test."

rebuild :	clean $(NAME)

all :
ifneq ($(BUFSIZE),$(DEFSIZE))
		touch main.cpp
		make		
endif
	


